package JXY02.Day03;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 要求用户输入若干员工信息，格式为：
 * name,age,gender,salary,hiredate;name,age,gender,salary,hiredate;....
 * 例如:
 * 张三,25,男,5000,2006-02-15;李四,26,女,6000,2007-12-24;...
 * 然后将每个员工信息解析成Emp对象。并存入到一个List集合中。
 * 并对集合排序，然后输出每个员工信息。
 *
 * 再根据员工的入职时间排序，入职晚的在前，早的在后并
 * 输出每个员工的信息。
 *
 */
public class Text03 {
    String str = "张三,30,男,5000,2006-02-15;李四,26,女,6000,2007-12-24;";
    public List<Text03Emp> getList(){

        //获得每个员工的字符串
        String s1 = ";";
        String[] workers = str.split(s1);

        List<String> arrayList = new ArrayList<>();
        List<Text03Emp> empList = new ArrayList<>();

        for (int i=0; i<workers.length; i++){
            arrayList.add(workers[i]);

        }

        for (int i=0; i<arrayList.size(); i++){
            //获得每个员工的每项值的字符串
            String workers_i = arrayList.get(i);
            String[] worker_i = workers_i.split(",");
            //将值给emp
            Text03Emp emp = new Text03Emp(worker_i[0],worker_i[1],worker_i[2],worker_i[3],worker_i[4]);
            empList.add(emp);
        }
        return empList;
    }




    public static void main(String[] args) throws Exception {
        Text03 text03 = new Text03();
        List<Text03Emp> emp = new ArrayList<>();
        emp = text03.getList();

        Collections.sort(emp);
        for (Text03Emp emp1 : emp){
            System.out.println(emp1.toString());
        }



    }


}


